import { get, post, put, del } from '@/utils/request'
import { Announcement, HelpItem, Carousel, PaginationResponse, ApiResponse } from '@/types'

// 公告管理API
export const announcementApi = {
  // 获取公告列表
  getList: (params: { page: number; limit: number; status?: string; type?: string; title?: string }) => {
    return get<PaginationResponse<Announcement>>('/announcements', params)
  },
  
  // 获取公告详情
  getDetail: (id: string) => {
    return get<Announcement>(`/announcements/${id}`)
  },
  
  // 创建公告
  create: (data: Partial<Announcement>) => {
    return post<Announcement>('/announcements', data)
  },
  
  // 更新公告
  update: (id: string, data: Partial<Announcement>) => {
    return put<Announcement>(`/announcements/${id}`, data)
  },
  
  // 删除公告
  delete: (id: string) => {
    return del<ApiResponse>(`/announcements/${id}`)
  },
  
  // 更新公告状态
  updateStatus: (id: string, status: 'draft' | 'published' | 'expired') => {
    return put<Announcement>(`/announcements/${id}/status`, { status })
  }
}

// 帮助中心API
export const helpApi = {
  // 获取帮助列表
  getList: (params: { page: number; pageSize: number; category?: string; status?: string; title?: string }) => {
    return get<PaginationResponse<HelpItem>>('/content/help', params)
  },
  
  // 获取帮助详情
  getDetail: (id: string) => {
    return get<HelpItem>(`/content/help/${id}`)
  },
  
  // 创建帮助
  create: (data: Partial<HelpItem>) => {
    return post<HelpItem>('/content/help', data)
  },
  
  // 更新帮助
  update: (id: string, data: Partial<HelpItem>) => {
    return put<HelpItem>(`/content/help/${id}`, data)
  },
  
  // 删除帮助
  delete: (id: string) => {
    return del<ApiResponse>(`/content/help/${id}`)
  },
  
  // 更新帮助状态
  updateStatus: (id: string, status: 'active' | 'inactive') => {
    return put<HelpItem>(`/content/help/${id}/status`, { status })
  }
}

// 帮助中心API（兼容旧用法）
export const helpCenterApi = helpApi

// 轮播图管理API
export const carouselApi = {
  // 获取轮播图列表
  getList: (params: { page: number; limit: number; type?: string; status?: string; title?: string }) => {
    return get<PaginationResponse<Carousel>>('/carousels', params)
  },
  
  // 获取轮播图详情
  getDetail: (id: string) => {
    return get<Carousel>(`/carousels/${id}`)
  },
  
  // 创建轮播图
  create: (data: Partial<Carousel>) => {
    return post<Carousel>('/carousels', data)
  },
  
  // 更新轮播图
  update: (id: string, data: Partial<Carousel>) => {
    return put<Carousel>(`/carousels/${id}`, data)
  },
  
  // 删除轮播图
  delete: (id: string) => {
    return del<ApiResponse>(`/carousels/${id}`)
  },
  
  // 更新轮播图状态
  updateStatus: (id: string, status: 'active' | 'inactive') => {
    return put<Carousel>(`/carousels/${id}/status`, { status })
  },
  
  // 更新轮播图排序
  updateSort: (id: string, sort: number) => {
    return put<Carousel>(`/carousels/${id}/sort`, { sort })
  },
  
  // 上传图片
  uploadImage: (formData: FormData) => {
    return post<{ url: string }>('/upload/image', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  }
} 